package com.bed.lovewithpatientbed.controller;

import com.bed.lovewithpatientbed.pojo.Role;
import com.bed.lovewithpatientbed.pojo.RoleBean;
import com.bed.lovewithpatientbed.service.RoleService;
import com.bed.lovewithpatientbed.util.LayUiUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Tyl
 * @version 1.0.0
 * @ClassName RoleController.java
 * @Description TODO
 * @createTime 2020年10月19日 12:13:00
 */
@Controller
@RequestMapping("role")
public class RoleController {
    @Resource
    RoleService roleService;
    /**
     * @description 主页
     * @author tyl
     * @updateTime 2020/10/19 16:51
     * @param
     */
    @RequestMapping("list")
    public String list(){
        return "role/list";
    }
    /**
     * @description 角色列表
     * @author tyl
     * @updateTime 2020/10/19 16:51
     * @param
     */
    @RequestMapping("listDo")
    @ResponseBody
    public Map<String, Object> selectRoleList(){
        List<Role> roleList = roleService.selectAll();
        List<RoleBean> roleBeanList = new ArrayList<>();
        for (Role role : roleList) {
            RoleBean roleBean = new RoleBean();
            roleBean.setRoleId(role.getRoleId());
            roleBean.setRoleName(role.getRoleName());
            roleBeanList.add(roleBean);
        }
        System.out.println(roleBeanList);
        return LayUiUtil.getLayTableResponseMap("success",0,roleList.size(),roleBeanList);
    }
    /**
     * @description 删除
     * @author tyl
     * @updateTime 2020/10/19 16:54
     * @param roleId:角色id
     */
    @RequestMapping("delete")
    @ResponseBody
    public String delete(Integer roleId){
        System.out.println("RoleController.delete");
        roleService.deleteRole(roleId);
        return "success";
    }
    /**
     * @description 增加
     * @author tyl
     * @updateTime 2020/10/19 16:54
     * @param role:角色
     */
    @RequestMapping("insertRole")
    @ResponseBody
    public String insertRole(Role role){
        roleService.insertRole(role);
        return "success";
    }
    /**
     * @description 查一个
     * @author tyl
     * @updateTime 2020/10/19 16:55
     * @param roleId:角色id
     */
    @RequestMapping("selectOne")
    @ResponseBody
    public Role selectOne(Integer roleId){
        Role role = roleService.selectOne(roleId);
        return role;
    }
    /**
     * @description 修改
     * @author tyl
     * @updateTime 2020/10/19 16:55
     * @param
     */
    @RequestMapping("update")
    @ResponseBody
    public String update(Role role){
        roleService.updateRole(role);
        return "success";
    }

}
